package com.chun.controller;

import com.chun.pojo.Emp;
import com.chun.pojo.Result;
import com.chun.service.EmpService;
import com.chun.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class loginController {
    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp) {
        Emp emp2 = empService.selectByName(emp);
        Map climas = new HashMap();
        climas.put("name", emp.getName());
        climas.put("id", emp.getId());
        if (emp2 != null) {
            String token = JwtUtils.generateJwt(climas);
            return Result.success(token);
        }
        return Result.error("用户名或密码错误");
        
    }
}
